//============================================================================
// Name        : strategy_pattern.cpp
// Author      : Tony
// Version     :
// Copyright   : GPLv2
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

class Strategy
{
public:
	virtual ~Strategy(){}
	virtual void algorithm() = 0;
};

class StrategyA : public Strategy
{
public:
	virtual void algorithm()
	{
		cout<<"use algorithm in StrategyA"<<endl;
	}
};

class StrategyB : public Strategy
{
	virtual void algorithm()
	{
		cout<<"use algorithm in StrategyB"<<endl;
	}
};


class Context
{
public:
	void setStrategy(Strategy* strategy)
	{
		_strategy = strategy;
	}

	void algorithm()
	{
		_strategy->algorithm();
	}
private:
	Strategy* _strategy;
};

int main() {
	Context* c = new Context();
	Strategy* s = new StrategyA();
	c->setStrategy(s);
	c->algorithm();
	delete s;

	cout<<"================="<<endl;
	s = new StrategyB();
	c->setStrategy(s);
	c->algorithm();

	delete s;
	delete c;
	return 0;
}
